package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.User;
import com.zr.service.DistributionRangePriceServiceLPN;
import com.zr.service.DistributionpriceServiceLPN;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class DistributionpriceActionLPN extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{
	private HttpServletRequest req;
	private HttpServletResponse resp;
	private Map<String, Object> session;
	private int page;
	private int rows;
	private Double disFirstKilogramPrice;
	private Double disNextKilogramPrice;
	private Double disFirstCubicPrice;
	private Double disNextCubicPrice;
	private String disRemarks;
	private String disState;
	private int dpIdf;
	private int	dpIds;
	private int	otId;
	private int disId;
	
	
	
	
	
	
	public int getDisId() {
		return disId;
	}

	public void setDisId(int disId) {
		this.disId = disId;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public Double getDisFirstKilogramPrice() {
		return disFirstKilogramPrice;
	}

	public void setDisFirstKilogramPrice(Double disFirstKilogramPrice) {
		this.disFirstKilogramPrice = disFirstKilogramPrice;
	}

	public Double getDisNextKilogramPrice() {
		return disNextKilogramPrice;
	}

	public void setDisNextKilogramPrice(Double disNextKilogramPrice) {
		this.disNextKilogramPrice = disNextKilogramPrice;
	}

	public Double getDisFirstCubicPrice() {
		return disFirstCubicPrice;
	}

	public void setDisFirstCubicPrice(Double disFirstCubicPrice) {
		this.disFirstCubicPrice = disFirstCubicPrice;
	}

	public Double getDisNextCubicPrice() {
		return disNextCubicPrice;
	}

	public void setDisNextCubicPrice(Double disNextCubicPrice) {
		this.disNextCubicPrice = disNextCubicPrice;
	}

	public String getDisRemarks() {
		return disRemarks;
	}

	public void setDisRemarks(String disRemarks) {
		this.disRemarks = disRemarks;
	}

	public String getDisState() {
		return disState;
	}

	public void setDisState(String disState) {
		this.disState = disState;
	}

	public int getDpIdf() {
		return dpIdf;
	}

	public void setDpIdf(int dpIdf) {
		this.dpIdf = dpIdf;
	}

	

	public int getDpIds() {
		return dpIds;
	}

	public void setDpIds(int dpIds) {
		this.dpIds = dpIds;
	}

	public int getOtId() {
		return otId;
	}

	public void setOtId(int otId) {
		this.otId = otId;
	}

			//属性注入
			@Resource
			private DistributionpriceServiceLPN disservice;
			
			
			/**
			 * 得到配送间价格
			 * @throws IOException
			 */
	public void getDis() throws IOException{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		User u=(User) session.get("user");
		
		JSONObject j = disservice.getDis(page, rows, u.getUid());
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
	}
	
	/**
	 * 增加配送间价格
	 * @throws IOException 
	 */
	public void insertDIS() throws IOException{
		boolean flag = disservice.insertDIS(disFirstKilogramPrice, disNextKilogramPrice, disFirstCubicPrice, disNextCubicPrice, disRemarks, disState, dpIdf, dpIds, otId);
		PrintWriter pw = resp.getWriter();
		if (flag) {
			pw.write("1");
		} else {
			pw.write("0");
		}
		pw.flush();
		pw.close();
	}
	
	/**
	 * 验证增加配送点时是否已存在
	 * @throws IOException 
	 */
	public  void validateAddDis() throws IOException{
		int i = disservice.finddisIdByDpidfAndDpidsAndOtid( dpIdf, dpIds, otId);
		PrintWriter pw = resp.getWriter();
		if (i>0) {
			pw.write("1");
		} else {
			pw.write("0");
		}
	}
	
	/**
	 * 修改配送点间价格
	 * @throws IOException 
	 */
	public void updateDIS() throws IOException{
		int i= disservice.updateDIS(disId, disFirstKilogramPrice, disNextKilogramPrice, disFirstCubicPrice, disNextCubicPrice, disRemarks);
		PrintWriter pw = resp.getWriter();
		if (i>0) {
			pw.write("1");
		} else {
			pw.write("0");
		}
	
				
	}
	
	
	
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.resp=arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.req=arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session=arg0;
	}

}
